library(survey)
library(stringr)

## run "PCM_cleaning.R"

date <- as.character(mil_conf.df$STARTDT)
date2 <- str_split_fixed(date, "/", 3)
mil_conf.df$month <- date2[,1]
mil_conf.df$day <- date2[,2]

mil_conf.df$jun_26_1 <- 1 # after Jun26
mil_conf.df$jun_26_1[mil_conf.df$day >= 18 & mil_conf.df$day <= 26] <- 0
mil_conf.df$jun_26_2 <- 1 # on or after Jun26
mil_conf.df$jun_26_2[mil_conf.df$day >= 18 & mil_conf.df$day < 26] <- 0

mil_conf.df$jun_29_1 <- 1 # after Jun29
mil_conf.df$jun_29_1[mil_conf.df$day >= 18 & mil_conf.df$day <= 29] <- 0
mil_conf.df$jun_29_2 <- 1 # on or after Jun29
mil_conf.df$jun_29_2[mil_conf.df$day >= 18 & mil_conf.df$day < 29] <- 0

mil_conf.df$jul_2_1 <- 1 # after Jul2
mil_conf.df$jul_2_1[mil_conf.df$day >= 2 & mil_conf.df$day <= 8] <- 0
mil_conf.df$jul_2_2 <- 1 # on or after Jul2
mil_conf.df$jul_2_2[mil_conf.df$day > 2 & mil_conf.df$day <= 8] <- 0

## Create weighted survey design object
milconf_design <-
  svydesign(
    id = ~ 1,
    weights = ~ weight,
    data = mil_conf.df
  )

## Test Q2B_1 (death of servicemember in Afghanistan)
svyttest(Q2B_1 ~ jun_26_1, milconf_design)
svyttest(Q2B_1 ~ jun_26_2, milconf_design)

## Test Q8-Q11
svyttest(Q8_d ~ jun_26_1, milconf_design)
svyttest(Q8_d ~ jun_26_2, milconf_design)
svyttest(Q8_d ~ jun_29_1, milconf_design)
svyttest(Q8_d ~ jun_29_2, milconf_design)
svyttest(Q8_d ~ jul_2_1, milconf_design)
svyttest(Q8_d ~ jul_2_2, milconf_design)

svyttest(Q9_m ~ jun_26_1, milconf_design)
svyttest(Q9_m ~ jun_26_2, milconf_design)
svyttest(Q9_m ~ jun_29_1, milconf_design)
svyttest(Q9_m ~ jun_29_2, milconf_design)
svyttest(Q9_m ~ jul_2_1, milconf_design)
svyttest(Q9_m ~ jul_2_2, milconf_design)

svyttest(Q10 ~ jun_26_1, milconf_design)
svyttest(Q10 ~ jun_26_2, milconf_design)
svyttest(Q10 ~ jun_29_1, milconf_design)
svyttest(Q10 ~ jun_29_2, milconf_design)
svyttest(Q10 ~ jul_2_1, milconf_design)
svyttest(Q10 ~ jul_2_2, milconf_design)

svyttest(Q10A_m ~ jun_26_1, milconf_design)
svyttest(Q10A_m ~ jun_26_2, milconf_design)
svyttest(Q10A_m ~ jun_29_1, milconf_design)
svyttest(Q10A_m ~ jun_29_2, milconf_design)
svyttest(Q10A_m ~ jul_2_1, milconf_design)
svyttest(Q10A_m ~ jul_2_2, milconf_design)

svyttest(Q11 ~ jun_26_1, milconf_design)
svyttest(Q11 ~ jun_26_2, milconf_design)
svyttest(Q11 ~ jun_29_1, milconf_design)
svyttest(Q11 ~ jun_29_2, milconf_design)
svyttest(Q11 ~ jul_2_1, milconf_design)
svyttest(Q11 ~ jul_2_2, milconf_design)

svyttest(Q11A_m ~ jun_26_1, milconf_design)
svyttest(Q11A_m ~ jun_26_2, milconf_design)
svyttest(Q11A_m ~ jun_29_1, milconf_design)
svyttest(Q11A_m ~ jun_29_2, milconf_design)
svyttest(Q11A_m ~ jul_2_1, milconf_design)
svyttest(Q11A_m ~ jul_2_2, milconf_design)

## Test Q12A-G
svyttest(Q12A_r2 ~ jun_26_1, milconf_design)
svyttest(Q12A_r2 ~ jun_26_2, milconf_design)
svyttest(Q12B_r2 ~ jun_26_1, milconf_design)
svyttest(Q12B_r2 ~ jun_26_2, milconf_design)
svyttest(Q12C_r2 ~ jun_26_1, milconf_design)
svyttest(Q12C_r2 ~ jun_26_2, milconf_design)
svyttest(Q12D_r2 ~ jun_26_1, milconf_design)
svyttest(Q12D_r2 ~ jun_26_2, milconf_design)
svyttest(Q12E_r2 ~ jun_26_1, milconf_design)
svyttest(Q12E_r2 ~ jun_26_2, milconf_design)
svyttest(Q12F_r2 ~ jun_26_1, milconf_design)
svyttest(Q12F_r2 ~ jun_26_2, milconf_design)
svyttest(Q12G_r2 ~ jun_26_1, milconf_design)
svyttest(Q12G_r2 ~ jun_26_2, milconf_design)

svyttest(Q12A_r2 ~ jun_29_1, milconf_design)
svyttest(Q12A_r2 ~ jun_29_2, milconf_design)
svyttest(Q12B_r2 ~ jun_29_1, milconf_design)
svyttest(Q12B_r2 ~ jun_29_2, milconf_design)
svyttest(Q12C_r2 ~ jun_29_1, milconf_design)
svyttest(Q12C_r2 ~ jun_29_2, milconf_design)
svyttest(Q12D_r2 ~ jun_29_1, milconf_design)
svyttest(Q12D_r2 ~ jun_29_2, milconf_design)
svyttest(Q12E_r2 ~ jun_29_1, milconf_design)
svyttest(Q12E_r2 ~ jun_29_2, milconf_design)
svyttest(Q12F_r2 ~ jun_29_1, milconf_design)
svyttest(Q12F_r2 ~ jun_29_2, milconf_design)
svyttest(Q12G_r2 ~ jun_29_1, milconf_design)
svyttest(Q12G_r2 ~ jun_29_2, milconf_design)

svyttest(Q12A_r2 ~ jul_2_1, milconf_design)
svyttest(Q12A_r2 ~ jul_2_2, milconf_design)
svyttest(Q12B_r2 ~ jul_2_1, milconf_design)
svyttest(Q12B_r2 ~ jul_2_2, milconf_design)
svyttest(Q12C_r2 ~ jul_2_1, milconf_design)
svyttest(Q12C_r2 ~ jul_2_2, milconf_design)
svyttest(Q12D_r2 ~ jul_2_1, milconf_design)
svyttest(Q12D_r2 ~ jul_2_2, milconf_design)
svyttest(Q12E_r2 ~ jul_2_1, milconf_design)
svyttest(Q12E_r2 ~ jul_2_2, milconf_design)
svyttest(Q12F_r2 ~ jul_2_1, milconf_design)
svyttest(Q12F_r2 ~ jul_2_2, milconf_design)
svyttest(Q12G_r2 ~ jul_2_1, milconf_design)
svyttest(Q12G_r2 ~ jul_2_2, milconf_design)

## Test Q41A-E
svyttest(Q41A_a ~ jun_26_1, milconf_design)
svyttest(Q41A_a ~ jun_26_2, milconf_design)
svyttest(Q41B_a ~ jun_26_1, milconf_design)
svyttest(Q41B_a ~ jun_26_2, milconf_design)
svyttest(Q41C_a ~ jun_26_1, milconf_design)
svyttest(Q41C_a ~ jun_26_2, milconf_design)
svyttest(Q41D ~ jun_26_1, milconf_design)
svyttest(Q41D ~ jun_26_2, milconf_design)
svyttest(Q41E ~ jun_26_1, milconf_design)
svyttest(Q41E ~ jun_26_2, milconf_design)

svyttest(Q41A_a ~ jun_29_1, milconf_design)
svyttest(Q41A_a ~ jun_29_2, milconf_design)
svyttest(Q41B_a ~ jun_29_1, milconf_design)
svyttest(Q41B_a ~ jun_29_2, milconf_design)
svyttest(Q41C_a ~ jun_29_1, milconf_design)
svyttest(Q41C_a ~ jun_29_2, milconf_design)
svyttest(Q41D ~ jun_29_1, milconf_design)
svyttest(Q41D ~ jun_29_2, milconf_design)
svyttest(Q41E ~ jun_29_1, milconf_design)
svyttest(Q41E ~ jun_29_2, milconf_design)

svyttest(Q41A_a ~ jul_2_1, milconf_design)
svyttest(Q41A_a ~ jul_2_2, milconf_design)
svyttest(Q41B_a ~ jul_2_1, milconf_design)
svyttest(Q41B_a ~ jul_2_2, milconf_design)
svyttest(Q41C_a ~ jul_2_1, milconf_design)
svyttest(Q41C_a ~ jul_2_2, milconf_design)
svyttest(Q41D ~ jul_2_1, milconf_design)
svyttest(Q41D ~ jul_2_2, milconf_design)
svyttest(Q41E ~ jul_2_1, milconf_design)
svyttest(Q41E ~ jul_2_2, milconf_design)

